package com.example.demo.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.ParseException;
import org.apache.hc.core5.http.io.entity.EntityUtils;

import java.io.IOException;

public class GetData {
    public static JSONObject getData(CloseableHttpResponse response) throws IOException, ParseException {
        JSONObject data=null;
        //解析响应
        if(response.getCode()== 200) {
            //获取响应体
            HttpEntity httpEntity = response.getEntity();
            //解析响应体
            String content = EntityUtils.toString(httpEntity, "utf-8");
            JSONObject jsonObject = JSON.parseObject(content);
//            System.out.println("1111111111111111111111111111111111111111111111");
//            System.out.println(jsonObject.toString());
//            System.out.println("1111111111111111111111111111111111111111111111");
            data = JSON.parseObject(jsonObject.getString("data"));
        }
        return data;
    }
}
